/**
 * 采购单管理管理初始化
 */
var Purchase = {
    id: "PurchaseTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Purchase.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '采购单号', field: 'purId', visible: true, align: 'center', valign: 'middle'},
            {title: '传真', field: 'purFax', visible: true, align: 'center', valign: 'middle'},
            {title: '负责人', field: 'purPic', visible: true, align: 'center', valign: 'middle'},
            {title: '负责人电话', field: 'purPicTel', visible: true, align: 'center', valign: 'middle'},
            {title: '供应商', field: 'purSupplier', visible: true, align: 'center', valign: 'middle'},
            {title: '供应商电话', field: 'purSupplierTel', visible: true, align: 'center', valign: 'middle'},
            {title: '收货地址', field: 'purAdress', visible: true, align: 'center', valign: 'middle'},
            {title: '付款方式', field: 'purPayType', visible: true, align: 'center', valign: 'middle'},
            {title: '采购日期', field: 'purDate', visible: true, align: 'center', valign: 'middle'},
            {title: '采购数量', field: 'purNumber', visible: true, align: 'center', valign: 'middle'},
            {title: '采购名称', field: 'purName', visible: true, align: 'center', valign: 'middle'},
            {title: '规格', field: 'purSpec', visible: true, align: 'center', valign: 'middle'},
            {title: '回购状态', field: 'purState', visible: true, align: 'center', valign: 'middle'},
            {title: '审核人', field: 'auditPersion', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '是否（审核）通过', field: 'auditPass', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '审核意见', field: 'auditOpinoin', visible: true, align: 'center', valign: 'middle',sortable: true}
    ];
};

/**
 * 检查是否选中
 */
Purchase.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Purchase.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加采购单管理
 */
Purchase.openAddPurchase = function () {
    var index = layer.open({
        type: 2,
        title: '添加采购单管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/purchase/purchase_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看采购单管理详情
 */
Purchase.openPurchaseDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '采购单管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/purchase/purchase_update/' + Purchase.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 打开查看采购单管理详情
 */
Purchase.openPurchaseState = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '采购单回购管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/purchase/purchase_state/' + Purchase.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除采购单管理
 */
Purchase.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/purchase/delete", function (data) {
            Feng.success("删除成功!");
            Purchase.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("purchaseId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询采购单管理列表
 */
Purchase.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Purchase.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Purchase.initColumn();
    var table = new BSTable(Purchase.id, "/purchase/list", defaultColunms);
    table.setPaginationType("client");
    Purchase.table = table.init();
});
